package com.yiren.dbaa.module.practice_set.line.presenter;

import android.app.Activity;

import com.yiren.backstage.config.api.LoadConfigApi;
import com.yiren.backstage.config.bean.device.UserParamConfigBean;
import com.yiren.backstage.currency.entity.LineInfoEntity;
import com.yiren.backstage.currency.entity.SiteEntity;
import com.yiren.dbaa.currency.api.CommonCallBack;
import com.yiren.dbaa.module.practice_set.line.contract.LineManageContract;
import com.yiren.dbaa.module.practice_set.line.model.LineManageModel;
import com.yiren.dbaa.view.toast.MessageBox;

/**
 * @author lwb
 * @date : 2022/11/16 15:28
 * @description: 线路管理
 */
public class LineManagePresenter implements LineManageContract.Presenter {

    private Activity activity;
    private LineManageContract.Model lineManageModel;
    private UserParamConfigBean userParamConfigBean;

    public LineManagePresenter(Activity activity) {
        this.activity = activity;
        lineManageModel = new LineManageModel(activity);
        userParamConfigBean = LoadConfigApi.loadUserParamConfig(activity);
    }

    @Override
    public void changeUserRange(LineManageContract.View view, LineInfoEntity lineInfo, int range) {
        lineManageModel.updateUserRange(userParamConfigBean.getUserInfo().getId().toString(), lineInfo, range, new CommonCallBack() {
            @Override
            public void success(Object result) {
                //本地修改
                lineManageModel.updateUserRangeLoacl(lineInfo, range);
                activity.runOnUiThread(() -> view.updateUseRange(range));
                MessageBox.show(activity, "更改成功!");
            }

            @Override
            public void fail(String error) {
                MessageBox.show(activity, error);
            }
        });
    }
}
